import {Column, Entity, JoinColumn, ManyToOne, PrimaryGeneratedColumn} from "typeorm";
import {BaseEntity} from "./BaseEntity";
import {ApiProperty} from "@nestjs/swagger";
import {Unit} from "./Unit";
import { type } from "os";
import { Goods } from "./Goods";

@Entity("goods_price")
export class GoodsPrice extends BaseEntity {
    @ApiProperty({description: "主键ID"})
    @PrimaryGeneratedColumn({comment: "主键ID"})
    id: number;

    @ApiProperty({description: "单位ID"})
    @Column({name: "unit_id", comment: "单位ID", nullable: true})
    unitId: number;

    @ApiProperty({description: "商品ID"})
    @Column({name: "goods_id", comment: "商品ID", nullable: true})
    goodsId: number;

    @ApiProperty({description: "价格"})
    @Column({comment: "价格", type: "double", scale: 2, nullable: true})
    price: number;

    /**
     * 关联关系
     */
    @ManyToOne(type => Unit, unit => unit.goodsPrice, {createForeignKeyConstraints: false})
    @JoinColumn({name: "unit_id", referencedColumnName: "unitId"})
    unit: Unit;

    @ManyToOne(type => Goods, goods => goods.goodsPriceList, {createForeignKeyConstraints: false})
    @JoinColumn({name: "goods_id", referencedColumnName: "id"})
    goods: Goods;
    
}
